package org.gap.jseed.contract;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Collection;

import org.gap.jseed.injection.ClassWriter;

public class NotEmptyValidation extends ValidationWriter {

	@Override
	public void injectBehavior(ClassWriter javaWriter, Method method, Annotation annotation) {
		Class<?>[] parameterTypes = method.getParameterTypes();
		for (int i = 0; i < parameterTypes.length; i++) {
			if (Collection.class.isAssignableFrom(parameterTypes[i])) {
				javaWriter.insertBefore(method, createTestCondition("!$" + (i + 1) + ".isEmpty()") +  createException("Collection was empty"));
				return;
			}
		}
	}
}
